package com.neuedu.elmserver.controller;


import com.neuedu.elmserver.pojo.Business;
import com.neuedu.elmserver.service.BusinessService;
import com.neuedu.elmserver.service.BusinesstypeService;
import com.neuedu.elmserver.utils.CategorizeBusinessRequest;
import com.neuedu.elmserver.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商家表 前端控制器
 * </p>
 *
 * @author wyh
 * @since 2024-11-07
 */
@RestController
@RequestMapping("/business")
@CrossOrigin
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    /**
     * 根据类型查询商家列表
     * @param typeId
     * @return
     */
    @GetMapping("/listBusinessByType")
    public ResultVO listBusinessByType(Integer typeId){
        return businessService.queryBusinessByType(typeId);
    }

    /**
     * 根据编号查询商家信息
     * @param id
     * @return
     */
    @GetMapping("/businessInfoById")
    public ResultVO businessInfoById(Integer id){
        return  businessService.queryBusinessById(id);
    }

    /**
     * 根据综合评分查询商家 （大到小）
     * @return
     */
    @GetMapping("/listBusinessByRemarks")
    public ResultVO listBusinessByRemarks(){
        return businessService.queryBusinessByRemarks();
    }

    /**
     * 根据距离查询商家 （小到大）
     * @return
     */
    @GetMapping("/listBusinessByDistance")
    public ResultVO listBusinessByDistance(){
        return businessService.queryBusinessByDistance();
    }

    /**
     * 根据销量查询商家 （大到小）
     * @return
     */
    @GetMapping("/listBusinessBySales")
    public ResultVO listBusinessBySales(){
        return businessService.queryBusinessBySales();
    }

    /**
     * 按商家类别筛选当前排序
     * @param request
     * @return
     */
    @PostMapping("/categorizeBusiness")
    public ResultVO categorizeBusiness(@RequestBody CategorizeBusinessRequest request) {
        List<Business> businessList = request.getBusinessList();
        Integer typeId = request.getTypeId();

        System.out.println("Business List: " + businessList);
        System.out.println("TypeId: " + typeId);

        return businessService.getCategorisedBusiness(businessList, typeId);
    }

    /**
     * 查询所有商家的数量
     * @return
     */
    @GetMapping("/getBusinessListCount")
    public ResultVO getBusinessListCount(){
        return  businessService.getAllBusinessListCount();
    }

    /**
     * 根据排行编号查询商家信息
     * @param
     * @return
     */
    @GetMapping("/queryByRankIdAsc")
    public ResultVO queryBusinessByRankIdAsc() {
        return businessService.queryBusinessByRankIdAsc();
    }


}